'use strict';

new Vue({
  el: '#root',

  data: {
    tab: 'signin',
    isShowPay: false,
    payType: 'union',
    isReadedAgreement: false,
    bornYears: [],
    bornMonths: [],
    bornDays: [],
    fee: 'feeA',
    isBannerFill: true,
    alert: {
      isEmailAlert: false,
      isPwAlert: false,
      isRePwAlert: false,
      isNameAlert: false
    },
    email: '',
    pw: '',
    rePw: '',
    name: ''
  },

  created: function created() {
    this.bornYears = this.getBornYears();
    this.bornMonths = this.getBornMonths();
    this.bornDays = this.getBornDays();
    var type = querystring(location.search.replace('?', '')).type;
    if (['signup', 'signin', 'forget'].indexOf(type) > -1) {
      this.tab = type;
    } else {
      this.tab = 'signin';
    }
  },


  methods: {
    onTapBuy: function onTapBuy() {
      this.isShowPay = true;
    },
    getBornYears: function getBornYears() {
      var currentYear = new Date().getFullYear();
      var years = [];
      for (var i = currentYear; i >= 1900; i--) {
        years.push(i);
      }
      return years;
    },
    getBornMonths: function getBornMonths() {
      var months = [];
      for (var i = 1; i <= 12; i++) {
        months.push(i);
      }
      return months;
    },
    getBornDays: function getBornDays() {
      var days = [];
      for (var i = 1; i <= 31; i++) {
        days.push(i);
      }
      return days;
    },
    onBlurEmail: function onBlurEmail(e) {
      this.alert.isEmailAlert = !/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.email);
    },
    onBlurPw: function onBlurPw(e) {
      this.alert.isPwAlert = this.pw.length < 6;
    },
    onBlurRePw: function onBlurRePw() {
      this.alert.isRePwAlert = this.rePw !== this.pw;
    },
    onBlurName: function onBlurName() {
      this.alert.isNameAlert = !this.name;
    }
  },

  mounted: function mounted() {
    document.querySelector('#root').style.background = '#fff';
  }
});